package Dao;

import Model.Student;
import UserView.UseUi;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class DaoStuHandle {
    public void showStuDAO(Student[] stus, int len) {//2
        System.out.println("学号\t姓名\t性别\t年龄\t专业\t\t\t时间");
        for (int i = 0; i < len; i++) {
            System.out.println(stus[i].getId()+"\t"+stus[i].getName()+"\t"+stus[i].getSex()
            +"\t"+stus[i].getAge()+"\t"+stus[i].getMajor()+"\t"+stus[i].getTime());
        }
    }

    public void addStuDAO(Student[] stus, Student stu) {
        stus[UseUi.num++] = stu;
    }

    public void delStuDAO(Student[] stus, Integer len, Integer w) {
        for (int i = w; i < len - 1; i++) {
            stus[i] = stus[i + 1];
        }
    }
    public void updateStuDAO(Student[]stus,Integer w){

        Student student =new Student();
        Scanner scanner = new Scanner(System.in);

        System.out.println("你要修改初始姓名是："+stus[w].getName());
        System.out.println("请输入你要修改的姓名：");
        String name =scanner.nextLine();
        if (name.equals("")){
            student.setName(stus[w].getName());
        }else {
            student.setName(name);
        }

        System.out.println("你要修改初始性别是："+stus[w].getSex());
        System.out.println("请输入你要修改的性别：");
        String sex =scanner.nextLine();
        if (sex.equals("")){
            student.setSex(stus[w].getSex());
        }else {
            student.setSex(sex);
        }


        System.out.println("你要修改初始年龄是："+stus[w].getAge());
        System.out.println("请输入你要修改的年龄：");
        String age =scanner.nextLine();
        if (age.equals("")){
            student.setAge(stus[w].getAge());
        }else {
            student.setAge(Integer.valueOf(age));
        }

        System.out.println("你要修改初始专业是："+stus[w].getMajor());
        System.out.println("请输入你要修改的专业：");
        String major=scanner.nextLine();
        if (major.equals("")){
            student.setMajor(stus[w].getMajor());
        }else {
            student.setMajor(major);
        }

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm：");
        String format =simpleDateFormat.format(date);
        student.setTime(format);
        student.setId(stus[w].getId());
        stus[w] = student;
    }
    public void xuehaoStuDAO(Student[] stus, int len){
        System.out.println("学号\t姓名\t性别\t年龄\t专业\t\t\t时间");
    }

}
